<?php
/*
  Document   : admin
  Created on : 12-mei-2011, 12:05:08
  Author     : Shahram abdi
  Description:
 */
?>
<div id="content">
    <?php
    require_once('../config/appvars.php');
    require_once('../config/config.php');

    // Make sure the user is logged in before going any further.
    if (!isset($_SESSION['user_id'])) {
        echo '<p class="login">Please <a href="../index.php?p=home">log in</a> to access this page.</p>';
        exit();
    }

    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

    if (isset($_POST['submit'])) {
        $province = $_POST['province'];
        $niveau = $_POST['niveau'];

        if (!empty($province) && !empty($niveau)) {
            $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, stagetitel, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving, logo FROM werkgeverprofiel WHERE provencie = '$province' AND stageniveau='$niveau' ";
            echo "<h4>Stages in $province en $niveau niveau:</h4>";
        } else {
            if (!empty($province)) {
                $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, stagetitel, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving, logo FROM werkgeverprofiel WHERE provencie = '$province'";
                echo "<h4>Stages in $province:</h4>";
            }
            if (!empty($niveau)) {
                $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, stagetitel, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving, logo FROM werkgeverprofiel WHERE stageniveau='$niveau'";
                echo "<h4>Stages $niveau niveau:</h4>";
            }
            if (empty($province) && empty($niveau)) {
                echo "<h4>Stages overzicht:</h4>";
                $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, stagetitel, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving, logo FROM werkgeverprofiel";
            }
        }

        $data = mysqli_query($dbc, $query);
        if (mysqli_num_rows($data) == 0) {
            echo 'Geen resultaten gevonden!';
        } else {
            while ($row = mysqli_fetch_array($data)) {
                if (!empty($row['stagetitel'])) {
                    echo '<div id="pro"><b>Werkgever:</b> ' . $row['instellingnaam'] . '<br/> ';
                    if (is_file(MM_UPLOADPATH . $row['logo']) && filesize(MM_UPLOADPATH . $row['logo']) > 0) {
                        echo '<div id="profoto"><img src="' . MM_UPLOADPATH . $row['logo'] . '" alt="' . $row['instellingnaam'] . '" /></div>';
                    }
                    echo '<b>Locatie(s):</b> ' . $row['woonplaats'] . ' in ' . $row['provencie'] . '<br/> ';
                    echo '<b>Soort werk:</b> ' . $row['stagetitel'] . '<br/> ';
                    echo '<b>Niveau:</b> ' . $row['stageniveau'] . '<br/> ';
                    echo '<b>Startdatum:</b> ' . $row['stagedatum'] . '<br/> ';
                    echo '<b>Omschrijving:</b> <br/>' . $row['omschrijving'] . '</div>';
                }
            }
        }
    } else {
        $query = "SELECT instellingnaam, adres, postcode, woonplaats, provencie, telefoon, email, stagetitel, stagetype, stageniveau, stageperiode, stagevergoeding, stagedatum , omschrijving, logo FROM werkgeverprofiel";
        $data = mysqli_query($dbc, $query);

        echo '<h4>Stages overzicht:</h4>';
        while ($row = mysqli_fetch_array($data)) {
            if (!empty($row['stagetitel'])) {

                echo '<div id="pro"><b>Werkgever:</b> ' . $row['instellingnaam'] . '<br/> ';
                if (is_file(MM_UPLOADPATH . $row['logo']) && filesize(MM_UPLOADPATH . $row['logo']) > 0) {
                    echo '<div id="profoto"><img src="' . MM_UPLOADPATH . $row['logo'] . '" alt="' . $row['instellingnaam'] . '" /></div>';
                }
                echo '<b>Locatie(s):</b> ' . $row['woonplaats'] . ' in ' . $row['provencie'] . '<br/> ';
                echo '<b>Soort werk:</b> ' . $row['stagetitel'] . '<br/> ';
                echo '<b>Niveau:</b> ' . $row['stageniveau'] . '<br/> ';
                echo '<b>Startdatum:</b> ' . $row['stagedatum'] . '<br/> ';
                echo '<b>Omschrijving:</b> <br/>' . $row['omschrijving'] . '</div>';
            }
        }
    }
    mysqli_close($dbc);
    ?>
</div>

<form method="post" action="index.php?p=zoekstage">
    <div id="sidebar">
        <h3>Zoek stages</h3>
        <ul>
            <li><p class="ti">Kies een provincie:</p>
                <select name="province" class="optie">
                    <option value="">Maakt niet uit</option>
                    <option value="Groningen" <?php if (!empty($province) && $province == 'Groningen')
        echo 'selected = "selected"'; ?>>Groningen</option>
                    <option value="Friesland" <?php if (!empty($province) && $province == 'Friesland')
                                echo 'selected = "selected"'; ?>>Friesland</option>
                    <option value="Drenthe" <?php if (!empty($province) && $province == 'Drenthe')
                                echo 'selected = "selected"'; ?>>Drenthe</option>
                    <option value="Overijssel" <?php if (!empty($province) && $province == 'Overijssel')
                                echo 'selected = "selected"'; ?>>Overijssel</option>
                    <option value="Flevoland" <?php if (!empty($province) && $province == 'Flevoland')
                                echo 'selected = "selected"'; ?>>Flevoland</option>
                    <option value="Gelderland" <?php if (!empty($province) && $province == 'Gelderland')
                                echo 'selected = "selected"'; ?>>Gelderland</option>
                    <option value="Utrecht" <?php if (!empty($province) && $province == 'Utrecht')
                                echo 'selected = "selected"'; ?> >Utrecht</option>
                    <option value="Noord-Holland" <?php if (!empty($province) && $province == 'Noord-Holland')
                                echo 'selected = "selected"'; ?>>Noord-Holland</option>
                    <option value="Zuid-Holland" <?php if (!empty($province) && $province == 'Zuid-Holland')
                                echo 'selected = "selected"'; ?>>Zuid-Holland</option>
                    <option value="Zeeland" <?php if (!empty($province) && $province == 'Zeeland')
                                echo 'selected = "selected"'; ?>>Zeeland</option>
                    <option value="Noord-Barabant" <?php if (!empty($province) && $province == 'Noord-Barabant')
                                echo 'selected = "selected"'; ?>>Noord-Barabant</option>
                    <option value="Limburg" <?php if (!empty($province) && $province == 'Limburg')
                                echo 'selected = "selected"'; ?>>Limburg</option>
                </select>
            </li>
            <li><p class="ti">Kies een niveau: </p>
                <select name="niveau" class="optie">
                    <option value="">Maakt niet uit</option>
                    <option value="MBO" <?php if (!empty($niveau) && $niveau == 'MBO')
                                echo 'selected = "selected"'; ?>>MBO</option>
                    <option value="HBO" <?php if (!empty($niveau) && $niveau == 'HBO')
                                echo 'selected = "selected"'; ?>>HBO</option>
                    <option value="WO" <?php if (!empty($niveau) && $niveau == 'WO')
                                echo 'selected = "selected"'; ?>>WO</option>
                </select>
            </li>

        </ul>
        <input type="submit" value="Zoek stages" name="submit" />
    </div></form>